<?php 
$dbconnect = DBconnect::getInstance();

function displayAllRealTeams(){
	$dbconnect = DBconnect::getInstance();
	$query = $dbconnect->getAllRealTeams();
	while($teams = mysql_fetch_array($query)){
		echo "<option value='".$teams['rteam_no']."'>".$teams['team_name']."</option>";
	}
}

function displayAllRealPlayers($teamno){
	$dbconnect = DBconnect::getInstance();
	$query = $dbconnect->getAllRealPlayers($teamno);
	if($query){
		echo "<form action='?page=DeletePlayer' method='post'><table>
			<tr><td>Select player to delete</td><td><select name='player' id='player'>";
		$i = 0;
		while($realplayers = mysql_fetch_row($query)){
			$player = mysql_result($query, $i);
			echo "<option value='$player'>$player</option>";
			$i++;
		}
		echo "</select></td><td><input type='submit' name='delete' value='Delete'></td></tr></table></form>";
	}
	else{
		echo "There aren't players from this team right now!";
	}
}

if(isset($_POST['selectteam'])){
		displayAllRealPlayers($_POST['allteams']);
}

if(isset($_POST['delete'])){
		unlink("../../images/realplayers/".$_POST['player'].".jpg");
		$dbconnect->deleteRealPlayer($_POST['player']);
		echo "Player is deleted successfully!";
}

	
?>		